package com.ruibei.ui;

import butterknife.ButterKnife;
import butterknife.InjectView;

import com.ruibei.R;
import com.ruibei.ui.fragment.WorkFragment;
import com.ruibei.ui.fragment.NewsFragment;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

/**
 * 主页面
 *
 * @author limingyan
 *
 */
public class MainActivity extends BaseActivity implements OnClickListener{
	private static final String TAG = "MainActivity";
	@InjectView(R.id.buttom_news)
	ImageButton mNewsImageBtn;
	
	@InjectView(R.id.buttom_work)
	ImageButton mWorkImageBtn;
	
//	@InjectView(R.id.buttom_opration)
//	ImageButton oprationImageBtn;
	
	//当前tab上显示的button
	private View currentButton;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.inject(this);
        initLisener();
    }
    
    private void initLisener(){
    	mNewsImageBtn.setOnClickListener(this);
    	mWorkImageBtn.setOnClickListener(this);
    	//oprationImageBtn.setOnClickListener(this);
    	
    	mWorkImageBtn.performClick();
    }
    @Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		//mEmptyLayout.showLoading();
		//mEmptyLayout.showError();
		//mEmptyLayout.showEmpty();
	}

	@Override
	public void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
	}
	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		super.onStop();
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		FragmentManager fm=getSupportFragmentManager();
		FragmentTransaction ft=fm.beginTransaction();
		switch (v.getId()) {
			case R.id.buttom_news:
				NewsFragment newsFragment = new NewsFragment();
				ft.replace(R.id.fl_content, newsFragment,MainActivity.TAG);
				ft.commit();
				setButton(v);
				break;
			case R.id.buttom_work:
				WorkFragment historyFragment = new WorkFragment();
				ft.replace(R.id.fl_content, historyFragment,MainActivity.TAG);
				ft.commit();
				setButton(v);
				break;
//			case R.id.buttom_opration:
//				OperationFragment operationFragment = new OperationFragment();
//				ft.replace(R.id.fl_content, operationFragment,MainActivity.TAG);
//				ft.commit();
//				setButton(v);
//				break;
		}
	}
	
	private void setButton(View v){
		if(currentButton!=null&&currentButton.getId()!=v.getId()){
			currentButton.setEnabled(true);
		}
		v.setEnabled(false);
		currentButton=v;
	}
    
}
